package api

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func sendErrorResponse(c *gin.Context, code int, message string, data any) {
	c.JSON(code, HttpResponse{
		Code:    code,
		Message: message,
		Data:    data,
	})
	c.Abort()
}
func sendSuccessResponse(c *gin.Context, code int, message string, data any) {
	c.JSON(code, HttpResponse{
		Code:    code,
		Message: message,
		Data:    data,
	})
}
func sendParameterError(c *gin.Context, data interface{}) {
	sendErrorResponse(c, http.StatusBadRequest, "参数错误", data)
}

func sendDatabaseError(c *gin.Context, data interface{}) {
	sendErrorResponse(c, http.StatusInternalServerError, "数据库操作错误", data)
}

func sendInternalServerError(c *gin.Context, data interface{}) {
	sendErrorResponse(c, http.StatusInternalServerError, "服务器内部错误", data)
}

func sendNotFound(c *gin.Context, data interface{}) {
	sendErrorResponse(c, http.StatusNotFound, "资源不存在", data)
}

func sendForbidden(c *gin.Context, data interface{}) {
	sendErrorResponse(c, http.StatusForbidden, "无权限访问", data)
}

func sendMethodNotAllowed(c *gin.Context, data interface{}) {
	sendErrorResponse(c, http.StatusMethodNotAllowed, "方法不允许", data)
}

func sendConflict(c *gin.Context, data interface{}) {
	sendErrorResponse(c, http.StatusConflict, "资源冲突", data)
}

func sendUnauthorized(c *gin.Context, data interface{}) {
	sendErrorResponse(c, http.StatusUnauthorized, "未授权", data)
}

func sendTooManyRequests(c *gin.Context, data interface{}) {
	sendErrorResponse(c, http.StatusTooManyRequests, "请求过于频繁", data)
}

func sendPaymentRequired(c *gin.Context, data interface{}) {
	sendErrorResponse(c, http.StatusPaymentRequired, "付款必需", data)
}

func sendNotAcceptable(c *gin.Context, data interface{}) {
	sendErrorResponse(c, http.StatusNotAcceptable, "无法接受", data)
}

func sendCreatedSuccess(c *gin.Context, data interface{}) {
	sendSuccessResponse(c, http.StatusCreated, "创建成功", data)
}

func sendUpdatedSuccess(c *gin.Context, data interface{}) {
	sendSuccessResponse(c, http.StatusOK, "更新成功", data)
}

func sendDeletedSuccess(c *gin.Context) {
	sendSuccessResponse(c, http.StatusOK, "删除成功", nil)
}

func sendQuerySuccess(c *gin.Context, data interface{}) {
	sendSuccessResponse(c, http.StatusOK, "查询成功", data)
}
